package com.community.contents.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.community.contents.entity.UserEntity;
import com.community.contents.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/getUserByMobile")
    public UserEntity getUserByMobile(@RequestParam("mobile") String mobile){
        QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile", mobile);
        return userService.getOne(queryWrapper);
    }

    @PostMapping("save")
    public UserEntity save(@RequestBody UserEntity userEntity){
        boolean save = userService.save(userEntity);
        return userEntity;
    }

    /**
     * 修改用戶头像
     * @param userEntity
     * @return
     */
    @PostMapping("/currentUserInfo")
    public boolean currentUserInfo(@RequestBody UserEntity userEntity){
        boolean b = userService.updateById(userEntity);
        return b;
    }

}
